<template>
  <div>
  </div>
</template>

<script>

export default {
  name: "sso_temp",
  data() {
    return {
      sessionid: "",
    };
  },
  watch: {
    $route: {
      handler: function(route) {
        console.log("新过渡页面路由监听route.query==",route.query);
        this.sessionid=route.query.sessionid;
        console.log("新过渡页面路由监听route.query.redirect==",route.query.redirect);
        this.redirect = route.query && route.query.redirect;
        console.log("新过渡页面路由监听this.redirect==",this.redirect);
        //this.sessionidSSO_login();//老孙的方法
      },
      immediate: true
    }
  },
  created() {
    this.sessionidSSO_login2();
  },
  methods: {
    sessionidSSO_login() {
      console.log("新过渡页面进入到sessionidSSO_login方法");
      //带sessionid的：/sso_temp?sessionid=PzkRf3xdSP31g09mQZXVLxocaXj7OtBr9FQ7xAeo6I1ak8EDHUrQ2x2JGw3RZn8C
      //不带，普通的：/index
      if(this.redirect==undefined || this.redirect.indexOf('=')==-1){ //采用正常的方式进入
        console.log("新过渡页面采用正常方式进入");
      }else{ //采用sessionid的方式进入
        var tts=this.redirect.split('=');
        var sessionid=tts[1];
        console.log("获取的sessionid参数==",sessionid); //这样就拿到了参数中的数据
        //var sessionid="PzkRf3xdSP31g09mQZXVLxocaXj7OtBr9FQ7xAeo6I1ak8EDHUrQ2x2JGw3RZn8C";
        // loginBySessionId(sessionid).then(res => {  //模仿Login的方式，调用src\store\modules\user.js中新写的SessionidLogin方法
        //   console.log("loginBySessionId返回值==",res);
        // });

        //模仿Login的方式，调用src\store\modules\user.js中新写的SessionidLogin方法
        this.$store.dispatch("SessionidLogin", sessionid).then(() => {
          console.log("this.redirect取值==",this.redirect);
          console.log("path:取值==",this.redirect || "/");
          //this.$router.push({ path: this.redirect || "/" }).catch(()=>{});//原先的代码
          this.$router.push({ path: "/" }).catch(()=>{});//实验代码
        }).catch(() => {
          this.loading = false;
          if (this.captchaEnabled) {
            this.getCode();
          }
        });
      }
    },
    sessionidSSO_login2(){
      this.$store.dispatch("SessionidLogin", this.sessionid).then(() => {
        console.log("this.redirect取值==",this.redirect);
        console.log("path:取值==",this.redirect || "/");
        //this.$router.push({ path: this.redirect || "/" }).catch(()=>{});//原先的代码
        this.$router.push({ path: "/" }).catch(()=>{});//实验代码
      }).catch(() => {

      });
    },
  }
};
</script>

<style rel="stylesheet/scss" lang="scss">
</style>
